package com.qbw.app.model;

import com.google.gson.Gson;
import com.qbw.app.Constant;
import com.qbw.l.L;
import com.qbw.log.XLog;

import java.io.Serializable;

/**
 * @author QBW
 * @date 2019/9/16
 */
public class Country extends BaseModel implements Serializable {

    private String countiresLetter;
    private String countriesAbbreviation;
    private int countriesId;
    private String countriesImgPath;
    private String countriesName;
    private String countriesName2;
    private String countriesNameEn;
    private int isShow;
    private String phoneJs;
    private int sort;
    private String telCode;

    public String getCountiresLetter() {
        return countiresLetter;
    }

    public void setCountiresLetter(String countiresLetter) {
        this.countiresLetter = countiresLetter;
    }

    public String getCountriesAbbreviation() {
        return countriesAbbreviation;
    }

    public void setCountriesAbbreviation(String countriesAbbreviation) {
        this.countriesAbbreviation = countriesAbbreviation;
    }

    public int getCountriesId() {
        return countriesId;
    }

    public void setCountriesId(int countriesId) {
        this.countriesId = countriesId;
    }

    public String getCountriesImgPath() {
        return countriesImgPath;
    }

    public void setCountriesImgPath(String countriesImgPath) {
        this.countriesImgPath = countriesImgPath;
    }

    public String getCountriesName() {
        return countriesName;
    }

    public void setCountriesName(String countriesName) {
        this.countriesName = countriesName;
    }

    public String getCountriesName2() {
        return countriesName2;
    }

    public void setCountriesName2(String countriesName2) {
        this.countriesName2 = countriesName2;
    }

    public String getCountriesNameEn() {
        return countriesNameEn;
    }

    public void setCountriesNameEn(String countriesNameEn) {
        this.countriesNameEn = countriesNameEn;
    }

    public int getIsShow() {
        return isShow;
    }

    public void setIsShow(int isShow) {
        this.isShow = isShow;
    }

    public String getPhoneJs() {
        return "^[0-9]+$";
        // 暂时不用正则表达式 20200219
        //return phoneJs;
    }

    public void setPhoneJs(String phoneJs) {
        this.phoneJs = phoneJs;
    }

    public int getSort() {
        return sort;
    }

    public void setSort(int sort) {
        this.sort = sort;
    }

    public String getTelCode() {
        return telCode;
    }

    public void setTelCode(String telCode) {
        this.telCode = telCode;
    }

    public static class Response extends BaseResponseList<Country> {

        public static Response fromJson(String meJson) {
            try {
                return new Gson().fromJson(meJson, Response.class);
            } catch (Exception e) {
                e.printStackTrace();
                L.GL.e(e);
            }
            return null;
        }

        public Country getCountry(String telCode) {
            int size = size();
            Country country = null;
            for (int i = 0; i < size; i++) {
                if (telCode.equals(getData().get(i).getTelCode())) {
                    country = getData().get(i);
                    break;
                }
            }
            return country;
        }

        public Country getCountry(int cid) {
            int size = size();
            Country country = null;
            for (int i = 0; i < size; i++) {
                if (cid == getData().get(i).getCountriesId()) {
                    country = getData().get(i);
                    break;
                }
            }
            return country;
        }
    }
}
